//! 分配结果定义

use core::{fmt::Display, result};

/// 分配错误
#[derive(Debug)]
#[allow(clippy::upper_case_acronyms)]
pub enum KallocError {
    /// 内存不粗
    ENOMEM,
    /// order 无效
    EORDER,
    /// 被分配
    EALLOCED,
    /// 检查错误
    ECHECK,
    /// 不是尾页
    ENOTAIL,
    /// 不是复合页
    ENOCOMP,
}

/// 分配结果
pub type Result<T> = result::Result<T, KallocError>;

impl Display for KallocError {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        let error = match self {
            Self::ENOMEM => "Out of memory",
            Self::EORDER => "Order invalid",
            Self::EALLOCED => "Alloced",
            Self::ECHECK => "Check at free flag(s) set",
            Self::ENOTAIL => "PageTail not set",
            Self::ENOCOMP => "Comp head not consistent",
        };
        write!(f, "{}", error)
    }
}
